package com.example.demo;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;

@SpringBootTest
@RunWith(SpringRunner.class)
public class OpForList {
    @Autowired
    RedisTemplate redisTemplate;
    @Test
    public void list1(){
        String [] strings=new String[]{"1","2","3"};
        redisTemplate.opsForList().leftPushAll("list",strings);
        System.out.println(redisTemplate.opsForList().range("list",0,-1));
    }
    @Test
    public void list2(){
        String [] strings=new String[]{"1","2","3"};
        redisTemplate.opsForList().leftPushAll("list",strings);
        System.out.println(redisTemplate.opsForList().size("list"));
    }
    @Test
    public void list3(){
        redisTemplate.opsForList().leftPush("list1","1");
        System.out.println(redisTemplate.opsForList().range("list1",0,-1));
        redisTemplate.opsForList().leftPush("list1","2");
        System.out.println(redisTemplate.opsForList().range("list1",0,-1));
        redisTemplate.opsForList().leftPush("list1","3");
        System.out.println(redisTemplate.opsForList().range("list1",0,-1));
        System.out.println(redisTemplate.opsForList().size("list1"));

    }
    @Test
    public void list4(){
        redisTemplate.opsForList().rightPush("list2","1");
        System.out.println(redisTemplate.opsForList().range("list2",0,-1));
        redisTemplate.opsForList().rightPush("list2","2");
        System.out.println(redisTemplate.opsForList().range("list2",0,-1));
        redisTemplate.opsForList().rightPush("list2","3");
        System.out.println(redisTemplate.opsForList().range("list2",0,-1));
        System.out.println(redisTemplate.opsForList().size("list2"));
    }
    @Test
    public void list5(){
        String [] strings=new String[]{"1","2","3"};
        redisTemplate.opsForList().rightPushAll("list",strings);
        System.out.println(redisTemplate.opsForList().range("list",0,-1));
    }
    @Test
    public void list6(){
        String [] strings=new String[]{"1","2","3"};
        redisTemplate.opsForList().rightPushAll("list6",strings);
        System.out.println(redisTemplate.opsForList().range("list6",0,-1));
        redisTemplate.opsForList().set("list6",1,"tihuan");
        System.out.println(redisTemplate.opsForList().range("list6",0,-1));
    }

    @Test
    public void list7(){
        String [] strings=new String[]{"1","2","2","2","2","3"};
        redisTemplate.opsForList().rightPushAll("list7",strings);
        System.out.println(redisTemplate.opsForList().range("list7",0,-1));
        redisTemplate.opsForList().remove("list7",1,"2");
        System.out.println(redisTemplate.opsForList().range("list7",0,-1));


    }
    @Test
    public void list8(){
        String [] strings=new String[]{"1","2","3"};
        redisTemplate.opsForList().rightPushAll("list8",strings);
        System.out.println(redisTemplate.opsForList().range("list8",0,-1));
        System.out.println(redisTemplate.opsForList().index("list8",2));
    }
    @Test
    public void list9(){
        String [] strings=new String[]{"1","2","3"};
        redisTemplate.opsForList().rightPushAll("list9",strings);
        System.out.println(redisTemplate.opsForList().range("list9",0,-1));
        System.out.println(redisTemplate.opsForList().leftPop("list9"));
        System.out.println(redisTemplate.opsForList().range("list9",0,-1));

    }
    @Test
    public void list10(){
        String [] strings=new String[]{"1","2","3"};
        redisTemplate.opsForList().rightPushAll("list10",strings);
        System.out.println(redisTemplate.opsForList().range("list10",0,-1));
        System.out.println(redisTemplate.opsForList().rightPop("list10"));
        System.out.println(redisTemplate.opsForList().range("list10",0,-1));

    }

}
